package com.ssy.jt808.gateway.infrastructure.gateway;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.ssy.jt808.gateway.domain.pojo.TerminalInfo;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/**
 * @author wangzezhou
 */
@Component
public class TerminalInfoCacheRepository{

  private Cache<String,TerminalInfo> terminalCache;

  public TerminalInfoCacheRepository(){
    terminalCache = Caffeine.newBuilder().expireAfterAccess(1, TimeUnit.HOURS).build();
  }

  public void setTerminalInfo( String phoneNo, TerminalInfo terminalInfo ){
    terminalCache.put(phoneNo, terminalInfo);
  }

  public TerminalInfo getTerminalInfo( String phoneNo ){
    return terminalCache.get(phoneNo, ( e )->null);
  }

//  public void evictTerminalInfo( String phoneNo ){
//    terminalCache.invalidate(phoneNo);
//  }
}
